package com.atguigu.sevicegateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * ClassName: GatewayConfiguration
 * Package: com.atguigu.sevicegateway.config
 * Description:
 *
 * @Author 刘强
 * @Create 2024/4/23 11:53
 * @Version 1.0
 */
@Configuration
public class GatewayConfiguration {
    @Bean
    public CorsWebFilter corsWebFilter(){
        UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
        CorsConfiguration corsConfig = new CorsConfiguration();
        corsConfig.addAllowedHeader("*");
        corsConfig.addAllowedMethod("*");
        corsConfig.addAllowedOrigin("*");
        corsConfig.setAllowCredentials(true);
        configSource.registerCorsConfiguration("/**",corsConfig);
        return new CorsWebFilter(configSource);
    }
}
